#include<bits/stdc++.h>
typedef long long ll;
const int MOD = 1e9+7;
using namespace std;
int qexp(int A, int B, int M) {
    if (B == 0) return 1;
    ll half = qexp(A, B / 2, M);
    (half *= half) %= M;
    if (B % 2) (half *= A) %= M;
    return half;
}

void solve() {
    int a, b, c; cin >> a >> b >> c;
    cout << qexp(a, qexp(b, c, MOD-1), MOD) << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int tc;cin>>tc;
  while(tc--) {
    solve();
  }
}
